package com.ghh.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.ghh.dao.MenuDao;
import com.ghh.dao.RoleDao;
import com.ghh.pojo.Menu;
import com.ghh.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.*;

@Service
public class MenuServiceImpl implements MenuService {

    @Autowired
    private MenuDao menuDao;
    @Autowired
    private RoleDao roleDao;

    @Override
    public List<Menu> findAll(String username) {

        //根据用户名获取角色id
        List<Integer> roleIds = roleDao.findByUsernmae(username);
        //获取菜单
        List<Menu> list = new ArrayList<>();
        //遍历角色集合
        for (Integer roleId : roleIds) {
            List<Menu> all = menuDao.findAll(roleId);
            for (Menu menu : all) {
                list.add(menu);
            }
        }
        return list;
    }
}
